package org.md.budzik.problems;

import java.math.BigInteger;

/**
 * Obsługa liczb Catalana.
 * @author Wiezzel
 *
 */
public class CatalanNumber extends OneArgOp {

	public CatalanNumber(Expression ex) {
		super(ex);
	}

	protected BigInteger computeOperation(BigInteger value) throws ParseException {
		if (value.compareTo(BigInteger.ZERO) < 0)
			throw new ParseException("Liczby Catalana są zdefiniowane dla x >= 0");
		if (value.equals(BigInteger.ZERO))
			return BigInteger.ONE;
		else
			return Binomial.binom(value.add(value), value).divide(value.add(BigInteger.ONE));
	}

	protected String operationSymbol() {
		return "catal";
	}

}
